package com.yc.cloud.mapper;

import com.yc.cloud.entity.HwCamera;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * <p>
 * 摄像头管理表 Mapper 接口
 * </p>
 *
 * @author kinggu
 * @since 2025-08-25
 */
@Mapper
public interface HwCameraMapper extends BaseMapper<HwCamera> {

    /**
     * 根据分组ID查询摄像头列表
     */
    default List<HwCamera> selectByGroupId(Long groupId) {
        return this.selectList(
            new QueryWrapper<HwCamera>()
                .eq(HwCamera.GroupId, groupId)
                .eq(HwCamera.IsDeleted, 0)
        );
    }

    /**
     * 统计分组下的摄像头数量
     */
    default Long countByGroupId(Long groupId) {
        return this.selectCount(
            new QueryWrapper<HwCamera>()
                .eq(HwCamera.GroupId, groupId)
                .eq(HwCamera.IsDeleted, 0)
        );
    }

    /**
     * 查询未分组的摄像头列表
     */
    default List<HwCamera> selectUngrouped() {
        return this.selectList(
            new QueryWrapper<HwCamera>()
                .isNull(HwCamera.GroupId)
                .eq(HwCamera.IsDeleted, 0)
        );
    }

    /**
     * 根据监视点ID查询摄像头列表
     */
    default List<HwCamera> selectByMonitoringPointId(Long monitoringPointId) {
        return this.selectList(
            new QueryWrapper<HwCamera>()
                .eq(HwCamera.MonitoringPointId, monitoringPointId)
                .eq(HwCamera.IsDeleted, 0)
        );
    }

    /**
     * 根据区域ID查询摄像头列表
     */
    default List<HwCamera> selectByRegionId(Long regionId) {
        return this.selectList(
            new QueryWrapper<HwCamera>()
                .eq(HwCamera.RegionId, regionId)
                .eq(HwCamera.IsDeleted, 0)
        );
    }

    /**
     * 统计监视点下的摄像头数量
     */
    default Long countByMonitoringPointId(Long monitoringPointId) {
        return this.selectCount(
            new QueryWrapper<HwCamera>()
                .eq(HwCamera.MonitoringPointId, monitoringPointId)
                .eq(HwCamera.IsDeleted, 0)
        );
    }

} 